# PyQuine
#
# Copyright (c) 2007 Alexis Couronne <www.skitoo.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
# 

import pmock,sqlobject
from core.player import *
from core.cardboard import Cardboard

class TestPlayer( pmock.MockTestCase ):
    
    def setUp(self):
        sqlobject.sqlhub.processConnection = sqlobject.connectionForURI( 'sqlite:/:memory:' )
        Player.createTable(ifNotExists=True)
        Cardboard.createTable(ifNotExists=True)
        self.instance = Player( name="Loulou", nickName="lulu", address="75, rue de labas", postalCode="63000", city="Clermont Ferrand", callNumber="0123456789", email="lulu@mail.com" )
        
    def tearDown(self):
        Player.dropTable()
        Cardboard.dropTable()
    
    def testPlayer(self):
        self.assertEquals( self.instance.name, "Loulou" )
        self.assertEquals( self.instance.nickName, "lulu" )
        self.assertEquals( self.instance.address, "75, rue de labas" )
        self.assertEquals( self.instance.postalCode, "63000" )
        self.assertEquals( self.instance.city, "Clermont Ferrand" )
        self.assertEquals( self.instance.callNumber, "0123456789" )
        self.assertEquals( self.instance.email, "lulu@mail.com" )
        
    def testPersistence(self):
        self.assertEquals( self.instance.id, 1 )
        player = Player.get(1)
        self.assertEquals( player, self.instance )
       
    def testSelectCardoard(self):
        cardboard1 = Cardboard( firstLine=(1,20,30,40,50), secondLine=(2,11,21,33,44), thirdLine=(12,23,49,65,82), player=self.instance )
        cardboard2 = Cardboard( firstLine=(1,20,30,41,50), secondLine=(2,11,22,33,44), thirdLine=(12,23,49,65,82), player=self.instance )
        self.assertEquals( len(self.instance.cardboards), 2 )
        self.assertEquals( self.instance.cardboards[0],cardboard1 )
        self.assertEquals( self.instance.cardboards[1],cardboard2 )